package com.aspire.moss.portal.view;

import java.util.List;
import java.util.Observable;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.aspire.moss.portal.R;

public class WorkspaceAdapter extends Observable {

	private Context mContext;

	private LayoutInflater inflater;

	private List<List<AppInfo>> apps;

	private OnClickListener itemClickListener;

	private OnLongClickListener itemLongClickListener;
	
	public static Bitmap deleteIcon;

	public WorkspaceAdapter(Context mContext, List<List<AppInfo>> apps) {
		this.mContext = mContext;
		this.apps = apps;
		inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		deleteIcon = ((BitmapDrawable)mContext.getResources().getDrawable(R.drawable.boxy_btn)).getBitmap();
	}

	public List<List<AppInfo>> getApps() {
		return apps;
	}

	public void setApps(List<List<AppInfo>> apps) {
		this.apps = apps;
	}

	public View getGroupView(ViewGroup parment, int index) {
		View cellLayout = null;
		cellLayout = inflater.inflate(R.layout.celllayou, null);
		return cellLayout;
	}

	public View getChildView(ViewGroup parment, int group, int index) {
		AppInfo info = apps.get(group).get(index);
		View view = inflater.inflate(R.layout.cell, null);
		view.setTag(info);
		((ImageView)view.findViewById(R.id.icon)).setImageBitmap(info.iconBitmap);
		((TextView)view.findViewById(R.id.title)).setText(info.title);
//		view.setLayoutParams(params);
//		view.appInfo = info;
		if (null != itemClickListener)
			view.setOnClickListener(itemClickListener);
		if (null != itemLongClickListener)
			view.setOnLongClickListener(itemLongClickListener);
		return view;
	}

	/**
	 * 得到有多少屏幕
	 * 
	 * @return
	 */
	public int getCount() {
		return apps.size();
	}

	/**
	 * 通知
	 */
	public void notifyObservers() {
		setChanged();
		notifyObservers(null);
	}

	public OnClickListener getItemClickListener() {
		return itemClickListener;
	}

	public void setItemClickListener(OnClickListener itemClickListener) {
		this.itemClickListener = itemClickListener;
	}

	public OnLongClickListener getItemLongClickListener() {
		return itemLongClickListener;
	}

	public void setItemLongClickListener(
			OnLongClickListener itemLongClickListener) {
		this.itemLongClickListener = itemLongClickListener;
	}

}
